public class test1 {
        public boolean isValid(String s) {
            //利用栈
            Stack<Character> stack = new Stack<>();
            //哈希存对应值
            HashMap<Character,Character> hashmap = new HashMap<>();
            hashmap.put('(',')');
            hashmap.put('[',']');
            hashmap.put('{','}');

            for(char ch:s.toCharArray()){
                if(hashmap.containsKey(ch)){
                    stack.push(ch);
                }else{
                    if(stack.isEmpty()){
                        return false;
                    }
                    if(hashmap.get(stack.peek())!=ch){
                        return false;
                    }else{
                        stack.pop();
                    }
                }
            }
            return stack.isEmpty();
        }
}
